/*
 * @lc app=leetcode.cn id=387 lang=swift
 *
 * [387] 字符串中的第一个唯一字符
 */

// @lc code=start
class Solution {
    func firstUniqChar(_ s: String) -> Int {
        var map: [Character: Int] = [Character: Int]()
        for c in s{
            if let count = map[c] {
                map[c] = count + 1
            }else{
                map[c] = 1
            }
        }
        
        for (index, c) in s.enumerated(){
            if map[c]! == 1 {
                return index
            }
        }
        return -1
    }
}
// @lc code=end

